﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using System.Windows.Input;

namespace WindowSwitcher.Converter
{
    [ValueConversion(typeof(Tuple<Behaviors.BindingsCollections, Behaviors.KeysCollections>), typeof(ObservableCollection<string>))]
    public class BindingsCollectionConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            ObservableCollection<string> enumerableList = null;
            var bindings = value as Tuple<Behaviors.BindingsCollections, Behaviors.KeysCollections>;

            if (bindings == null)
                return enumerableList;

            if ((parameter as string) == "Handle")
            {
                enumerableList = new ObservableCollection<string>(bindings.Item1.Where(x => x.Enabled == true).Select(x => x.HandleName).ToList());
            }
            else if ((parameter as string) == "Key")
            {
                enumerableList = new ObservableCollection<string>(bindings.Item2.Where(x => x.Enabled == true).Select(x => x.Key.ToString()).ToList());
            }
            else
                throw new NotSupportedException("Parameter is not supported !");

            return enumerableList;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
